import { useTable, LIST_TYPE } from '@crud/index';
import { getDiscountList } from '@/api/crm-agency/kgj/lecturer';
import dayjs from 'dayjs';
// 查询
const levelMap: Record<string, any> = {
  10: '轻享版',
  20: '旗舰版',
  30: '至尊版'
};
// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '排名', prop: 'rank', minWidth: 100, fixed: 'left' },
    { label: '讲师名称', prop: 'agent_name', minWidth: 120 },
    { label: '讲师手机号', prop: 'agent_mobile', minWidth: 120 },
    { label: '会员版本', prop: 'vip_level', minWidth: 120, render: (s: any) => levelMap[s.row.vip_level] || '-' },
    { label: '活动折扣', prop: 'discount', minWidth: 120 },
    { label: '创建时间', prop: 'add_time', minWidth: 177, type: 'dateTime' },
    { label: '失效时间', prop: 'invalid_time', minWidth: 177, type: 'dateTime' },
    { label: '创建人', prop: 'creater', minWidth: 120 },
    { label: '操作', prop: 'actions', minWidth: 120, render: 'actions' }
  ];
  const timeChange = (values:any[]) => {
    let from = undefined;
    let to = undefined;
    if (values && values.length > 0) {
      from = dayjs(values[0]).startOf('day').format('X').valueOf();
      to = dayjs(values[1]).endOf('day').format('X').valueOf();
    }
    return { from, to };
  };
  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      keyword: '',
      creater: '',
      begin_time: undefined,
      end_time: undefined
    },
    columns: columns,
    getList: ({ data, params }:{data: Record<string, any>, params: any}) => {
      const { keyword, creater, _dateRange } = data;
      let { begin_time, end_time } = params;
      const { from, to } = timeChange(_dateRange);
      begin_time = from;
      end_time = to;
      data = { keyword, creater, begin_time, end_time };
      return getDiscountList({ data, params });
    }
  });
};
